﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace AncientEmpires_025_132
{
    public class ListCellsMoveEffect : VisibleGameEntity
    {
        private List<CellMoveEffect> _listCells;
        public List<CellMoveEffect> ListCells
        {
            get { return _listCells; }
            set { _listCells = value; }
        }
        private ContentManager _content;
        public ContentManager Content
        {
            get { return _content; }
            set { _content = value; }
        }
        private string[] _strTexture;
        public string[] StrTexture
        {
            get { return _strTexture; }
            set { _strTexture = value; }
        }
        private Vector2 _sizeCell;
        public Vector2 SizeCell
        {
            get { return _sizeCell; }
            set { _sizeCell = value; }
        }
        private Cell[,] _cells;
        public Cell[,] Cells
        {
            get { return _cells; }
            set { _cells = value; }
        }
        public ListCellsMoveEffect(ContentManager content, string[] strTexture, Vector2 sizeCell)
        {
            ListCells = new List<CellMoveEffect>();
            Content = content;
            StrTexture = strTexture;
            SizeCell = sizeCell;

        }

       

        public void InitCellsEffect(List<Vector2> listIndexCell)
        {
            ListCells.Clear();
            Vector2 tempPos = new Vector2();
            for (int i = 0; i < listIndexCell.Count; i++)
            {
                tempPos = new Vector2(listIndexCell[i].Y * MapWithCell.CELL_HEIGHT, listIndexCell[i].X * MapWithCell.CELL_WIDTH);
                ListCells.Add(new CellMoveEffect(Content, StrTexture, 
                                                    Cells[(int)listIndexCell[i].X, (int)listIndexCell[i].Y].ListSprites[Cells[(int)listIndexCell[i].X, (int)listIndexCell[i].Y].ISprite].Position,
                                                    Cells[(int)listIndexCell[i].X, (int)listIndexCell[i].Y].ListSprites[Cells[(int)listIndexCell[i].X, (int)listIndexCell[i].Y].ISprite].TopLeft,
                                                    SizeCell));
            }
        }

        public void AppendCellsEffect(List<Vector2> listIndexCell)
        {
            Vector2 tempPos = new Vector2();
            for (int i = 0; i < listIndexCell.Count; i++)
            {
                tempPos = new Vector2(listIndexCell[i].Y * MapWithCell.CELL_HEIGHT, listIndexCell[i].X * MapWithCell.CELL_WIDTH);
                ListCells.Add(new CellMoveEffect(Content, StrTexture,
                                                    Cells[(int)listIndexCell[i].X, (int)listIndexCell[i].Y].ListSprites[Cells[(int)listIndexCell[i].X, (int)listIndexCell[i].Y].ISprite].Position,
                                                    Cells[(int)listIndexCell[i].X, (int)listIndexCell[i].Y].ListSprites[Cells[(int)listIndexCell[i].X, (int)listIndexCell[i].Y].ISprite].TopLeft,
                                                    SizeCell));
                ListCells[ListCells.Count - 1].IsMove = false;
            }
        }

        public void SetTopLeft(Vector2 temp)
        {
            for (int i = 0; i < ListCells.Count; i++)
            {
                for (int j = 0; j < ListCells[i].ListSprites.Count; j++)
                {
                    ListCells[i].ListSprites[j].TopLeft += temp;    
                }
            }
        }
        public override void Update(GameTime gametime)
        {
            for (int i = 0; i < ListCells.Count; i++)
            {
                ListCells[i].Update(gametime);
            }
        }
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            for (int i = 0; i < ListCells.Count; i++)
            {
                ListCells[i].Draw(gameTime, spriteBatch);
            }
        }
    }
}
